<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/Server for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Server\Controller;

use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;

class ContatoRestController extends AbstractRestfulController
{
    
    public function get($id) {
        
        $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        $repo = $em->getRepository('Server\Entity\Contato');
        
        $contato = $repo->find($id);
        
        return new JsonModel(
            array(
                'nome' => $contato->getNome(), 
                'email' => $contato->getEmail()
            )
        );
    }
    
    
    public function getList() {
        
        $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
        $repo = $em->getRepository('Server\Entity\Contato');
        
        $contatos = $repo->findAll();
        $data = array();

        foreach ( $contatos as $contato ) {
            $data['data'][] = array(
            	'nome'     => $contato->getNome(),
                'email'    => $contato->getEmail(),
                'telefone' => $contato->getTelefone()
            );   
        }
        
        return new JsonModel($data);
    }
    
    public function create($data) {}

    public function delete($id) {}
    
    public function update($id, $data) {}
}
